import request from '@/utils/request'

// 查询用户书架列表
export function listBookshelf(query) {
  return request({
    url: '/bookshelf/bookshelf/list',
    method: 'get',
    params: query
  })
}

// 查询用户书架详细
export function getBookshelf(userId) {
  return request({
    url: '/bookshelf/bookshelf/' + userId,
    method: 'get'
  })
}

// 新增用户书架
export function addBookshelf(data) {
  return request({
    url: '/bookshelf/bookshelf',
    method: 'post',
    data: data
  })
}

// 修改用户书架
export function updateBookshelf(data) {
  return request({
    url: '/bookshelf/bookshelf',
    method: 'put',
    data: data
  })
}

// 删除用户书架
export function delBookshelf(userId) {
  return request({
    url: '/bookshelf/bookshelf/' + userId,
    method: 'delete'
  })
}
// 根据用户id查询书架信息
export function getBookShelfByUserId(userId) {
  return request({
    url: '/novel/bookshelf/getBookShelfByUserId',
    method: 'get',
    params: { userId }
  })
}

export function ListByIntelligent(userId) {
  return request({
    url: '/novel/bookshelf/ListByIntelligent',
    method: 'get',
    params: { userId }
  })
}

// 查询小说内容
export function getNovelContent(title) {
  return request({
    url: '/novel/read/getNovelContent',
    method: 'get',
    params: { 
      title,
      exact: true  // 添加精确匹配参数
    }
  })
}

// 查询小说章节
export function getNovelChapter(title) {
  return request({
    url: '/novel/read/getNovelChapter',
    method: 'get',
    params: { title }
  })
}
// 添加收藏
export function addCollection(data) {
  return request({
    url: '/novel/collection/add',
    method: 'post',
    params: {
      userId: data.userId,
      novelName: data.novelName
    }
  })
}

// 取消收藏
export function cancelCollection(data) {
  return request({
    url: '/novel/collection/cancel',
    method: 'delete',
    params: {
      userId: data.userId,
      novelName: data.novelName
    }
  })
}

// 检查是否已收藏
export function isCollection(data) {
  return request({
    url: '/novel/collection/isCollection',
    method: 'post',
    params: {
      userId: data.userId,
      novelName: data.novelName
    }
  })
} 
// 获取章节内容（读者）
export function getChapterContent(novelName, orderNum, userId) {
  return request({
    url: '/novel/chapter/content',
    method: 'get',
    params: {
      title: novelName,
      orderNum: orderNum,
      userId: userId
    }
  })
}

// 获取章节内容（作者）
export function getContentForAuthor(novelName, orderNum) {
  return request({
    url: '/novel/chapter/contentForAuthor',
    method: 'get',
    params: {
      title: novelName,
      orderNum: orderNum
    }
  })
}



// 获取下一章信息
export function getNextChapter(title, orderNum,userId) {
  return request({
    url: '/novel/chapter/isChapter',
    method: 'get',
    params: {
      title,
      orderNum,
      userId
    }
  })
}

// 获取上一章信息
export function getPreChapter(title, orderNum,userId) {
  return request({
    url: '/novel/chapter/preChapter',
    method: 'get',
    params: {
      title,
      orderNum,
      userId
    }
  })
}
// 查询小说评论
export function getCommentList(title) {
  return request({
    url: '/writer/comment/getCommentList',
    method: 'post',
    params: {
      title
    }
  })
}
// 添加评论
export function addComment(data) {
  return request({
    url: '/writer/comment/addComment',
    method: 'post',
    data: data
  })
}
// 删除评论
export function deleteComment(CommentID) {
  return request({
    url: '/writer/comment/deleteComment',
    method: 'post',
    params: {
      CommentID: CommentID
    }
  })
}

// 查询未订阅的小说章节
export function getSubscribeList(userId,title) {
  return request({
    url: 'points/points/getSubscribeList',
    method: 'get',
    params: { userId,title }
  })
}
// 批量订阅小说章节
export function subscribe(data) {
  return request({
    url: 'points/points/subscribe',
    method: 'put',
    data: data
  })
}
// 打赏月票
export function pass(data) {
  return request({
    url: 'points/points/pass',
    method: 'put',
    data: data
  })
}
//添加到书架
export function addBookShelf(userId,title) {
  return request({
    url: '/novel/bookshelf/addBookShelf',
    method: 'put',
    params: {
      userId,
      title
    }
  })
}
// 查询该书是否在书架中
export function isInBookShelf(userId,title) {
  return request({
    url: '/novel/bookshelf/isInBookShelf',
    method: 'get',
    params: { userId,title }
  })
}

/**
 * 删除书架
 * @param {Object} data 删除参数
 * @param {number} data.userId 用户ID
 * @param {string} data.title 小说标题
 */
export function deleteBookShelf(data) {
  return request({
    url: '/novel/bookshelf/deleteBookShelf',
    method: 'delete',
    data: data
  })
}

/**
 * 批量删除书架
 * @param {Object} data 删除参数
 * @param {number} data.userId 用户ID
 * @param {string[]} data.titles 小说标题数组
 */
export function deleteBatchBookShelf(data) {
  return request({
    url: '/novel/bookshelf/deleteBatchBookShelf',
    method: 'delete',
    data: data
  })
}